package suanfa.lianxi;

public class fanzhuanLink {
    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }
    public ListNode reverseList(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;
        while(cur!=null){
            ListNode temp = cur.next; //保存当前节点下一个节点
            cur.next = pre;//指向前一个节点（头结点指向null）
            pre = cur;
            cur = temp;
        }
        return pre;
    }

}
